package com.wilmer.schedule.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.wilmer.schedule.domain.vo.StudentListByCourseIdVO;
import com.wilmer.schedule.domain.vo.YwClassScheduleVO;
import io.lettuce.core.dynamic.annotation.Param;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.wilmer.common.annotation.Log;
import com.wilmer.common.core.controller.BaseController;
import com.wilmer.common.core.domain.AjaxResult;
import com.wilmer.common.enums.BusinessType;
import com.wilmer.schedule.domain.YwClassSchedule;
import com.wilmer.schedule.service.IYwClassScheduleService;
import com.wilmer.common.utils.poi.ExcelUtil;
import com.wilmer.common.core.page.TableDataInfo;

/**
 * 课程管理Controller
 *
 * @author zl
 * @date 2024-04-10
 */
@RestController
@RequestMapping("/schedule/schedule")
public class YwClassScheduleController extends BaseController {
    @Autowired
    private IYwClassScheduleService ywClassScheduleService;

    /**
     * 查询可添加学生列表（根据部门查询）
     */
    @GetMapping("/selectStudentUserByDeptId")
    public AjaxResult selectStudentUserByDeptId() {
        return success(ywClassScheduleService.selectStudentUserByDeptId());
    }

    /**
     * 课程添加学生
     */
    @PostMapping("/addStudent")
    public AjaxResult addStudent(@RequestBody YwClassScheduleVO ywClassScheduleVO) {
        return toAjax(ywClassScheduleService.addStudent(ywClassScheduleVO));
    }
    /**
     * 删除课程学生
     */
    @GetMapping("/deleteStudent")
    public AjaxResult deleteStudent(YwClassScheduleVO ywClassScheduleVO) {
        return toAjax(ywClassScheduleService.deleteStudent(ywClassScheduleVO));
    }
    /**
     * 查询课程学生
     */
    @GetMapping("/studentListByCourseId")
    public TableDataInfo studentListByCourseId(@Param("courseId") Long courseId) {
        startPage();
        List<StudentListByCourseIdVO> list = ywClassScheduleService.studentListByCourseId(courseId);
        return getDataTable(list);
    }

    /**
     * 查询课程管理列表
     */
    @PreAuthorize("@ss.hasPermi('schedule:schedule:list')")
    @GetMapping("/list")
    public TableDataInfo list(YwClassSchedule ywClassSchedule) {
        startPage();
        List<YwClassSchedule> list = ywClassScheduleService.selectYwClassScheduleList(ywClassSchedule);
        return getDataTable(list);
    }

    /**
     * 导出课程管理列表
     */
    @PreAuthorize("@ss.hasPermi('schedule:schedule:export')")
    @Log(title = "课程管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YwClassSchedule ywClassSchedule) {
        List<YwClassSchedule> list = ywClassScheduleService.selectYwClassScheduleList(ywClassSchedule);
        ExcelUtil<YwClassSchedule> util = new ExcelUtil<YwClassSchedule>(YwClassSchedule.class);
        util.exportExcel(response, list, "课程管理数据");
    }

    /**
     * 获取课程管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('schedule:schedule:query')")
    @GetMapping(value = "/{courseId}")
    public AjaxResult getInfo(@PathVariable("courseId") Long courseId) {
        return success(ywClassScheduleService.selectYwClassScheduleByCourseId(courseId));
    }

    /**
     * 新增课程管理
     */
    @PreAuthorize("@ss.hasPermi('schedule:schedule:add')")
    @Log(title = "课程管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YwClassSchedule ywClassSchedule) {
        return toAjax(ywClassScheduleService.insertYwClassSchedule(ywClassSchedule));
    }

    /**
     * 修改课程管理
     */
    @PreAuthorize("@ss.hasPermi('schedule:schedule:edit')")
    @Log(title = "课程管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YwClassSchedule ywClassSchedule) {
        return toAjax(ywClassScheduleService.updateYwClassSchedule(ywClassSchedule));
    }

    /**
     * 删除课程管理
     */
    @PreAuthorize("@ss.hasPermi('schedule:schedule:remove')")
    @Log(title = "课程管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{courseIds}")
    public AjaxResult remove(@PathVariable Long[] courseIds) {
        return toAjax(ywClassScheduleService.deleteYwClassScheduleByCourseIds(courseIds));
    }
}
